from fastapi import APIRouter, HTTPException, Depends
from typing import List, Optional, Dict, Any
import time
import uuid
from pydantic import BaseModel

from ..models import ChatCompletionRequest, ChatCompletionResponse, CompletionRequest, CompletionResponse
from ..config import settings


router = APIRouter()


@router.post("/chat/completions")
async def create_chat_completion(request: ChatCompletionRequest):
    """Create a chat completion using the loaded model."""
    model_manager = request.app.state.model_manager
    
    # Generate the response using the selected backend
    response = await model_manager.generate_chat_completion(request)
    
    return response


@router.post("/completions")
async def create_completion(request: CompletionRequest):
    """Create a completion using the loaded model."""
    model_manager = request.app.state.model_manager
    
    response = await model_manager.generate_completion(request)
    
    return response


@router.get("/models")
async def list_models():
    """List available models."""
    model_manager = request.app.state.model_manager
    return {
        "object": "list",
        "data": [
            {
                "id": settings.model_name,
                "object": "model",
                "created": int(time.time()),
                "owned_by": "bigserver"
            }
        ]
    }